#include "MatchProcParamCollectRequestModel.h"



namespace MesModel {

MatchProcParamCollectRequestModel::MatchProcParamCollectRequestModel(QString factoryNo, QString transId, QDateTime eventTime, QString eventUser, QString machineNo, QList<MatchProcParamCollectRequestParamInfo> paramInfo)
    :factoryNo(factoryNo),transId(transId),eventTime(eventTime),eventUser(eventUser),machineNo(machineNo),paramInfo(paramInfo)
{

}

void MatchProcParamCollectRequestModel::fromJson(const QJsonObject &json)
{
    factoryNo = json["factoryNo"].toString();
    transId = json["transId"].toString();
    eventTime = QDateTime::fromString(json["eventTime"].toString());
    eventUser = json["eventUser"].toString();
    machineNo = json["machineNo"].toString();
    workStep = json["workStep"].toString();
    location = json["location"].toString();
    const QJsonArray param_info_list = json["paramInfo"].toArray();
    for(const auto&item: param_info_list)
    {
        MatchProcParamCollectRequestParamInfo param_info;
        param_info.fromJson(item.toObject());
        paramInfo.append(param_info);
    }

}

QJsonObject MatchProcParamCollectRequestModel::toJson() const
{
    QJsonObject json;
    json["factoryNo"] = factoryNo;
    int randomNumber = QRandomGenerator::global()->bounded(10000,100000);
    json["transId"] = QString("%1%2").arg(QDateTime::currentDateTime().toString("yyyyMMddhhmmssSSS")).arg(randomNumber);
    json["eventTime"]=QDateTime::currentDateTime().toString("yyyy-mm-dd hh:mm:ss");
    json["eventUser"] = eventUser;
    json["machineNo"] = machineNo;

    QJsonArray param_info_list;
    for(const auto& item:paramInfo)
    {
        param_info_list.append(item.toJson());
    }
    json["paramInfo"] = param_info_list;
    return json;

}


MatchProcParamCollectRequestParamInfo::MatchProcParamCollectRequestParamInfo(QString pcu, QList<MatchProcParamCollectRequestParamList> paramList):pcu(pcu),paramList(paramList){}

void MatchProcParamCollectRequestParamInfo::fromJson(const QJsonObject &json)
{
    pcu = json["pcu"].toString();
    const QJsonArray param_list = json["pramList"].toArray();

    for(const auto& item:param_list)
    {
        MatchProcParamCollectRequestParamList param_item;
        param_item.fromJson(item.toObject());
        paramList.append(param_item);

    }

}

QJsonObject MatchProcParamCollectRequestParamInfo::toJson() const
{
    QJsonObject json;
    json["pcu"] = pcu;
    QJsonArray param_list;
    for(const auto&item:paramList)
    {
        param_list.append(item.toJson());
    }
    json["paramList"] = param_list;
    return json;
}



MatchProcParamCollectRequestParamList::MatchProcParamCollectRequestParamList(QString k, QString v, QString seq, QString location)
    :paramKey(k),paramValue(v),seq(seq),location(location)
{

}

void MatchProcParamCollectRequestParamList::fromJson(const QJsonObject &json)
{
    paramKey = json["k"].toString();
    paramValue = json["v"].toString();
    seq = json["seq"].toString();
    location = json["location"].toString();
}

QJsonObject MatchProcParamCollectRequestParamList::toJson() const
{
    QJsonObject json;
    json["k"] = paramKey;
    json["v"] = paramValue;
    json["seq"] = seq;
    json["location"] = location;
    return json;
}

}
